{include file="header"}
<div class="x-nav">
    <a>
        <cite style="font-size: 18px;">修改角色</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" name="id" value="{$item.id}">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>{:lang('roles')}{:lang('name')}
                </label>
                <div class="layui-input-block">
                    <input type="text" name="name" placeholder="{:lang('please.enter')}{:lang('roles')}{:lang('name')}" autocomplete="off" class="layui-input" value="{$item.name}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red"></span>{:lang('roles')}{:lang('desc')}
                </label>
                <div class="layui-input-block">
                    <textarea name="desc" placeholder="{:lang('please.enter')}{:lang('roles')}{:lang('desc')}" class="layui-textarea">{$item.desc}</textarea>

                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title">
                <legend>{:lang('purview')}</legend>
                <div class="layui-field-box">
                    {foreach $purviews as $key=>$item}
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red"></span>{$item.name}
                        </label>
                        <div class="layui-input-block">
                            {foreach $item.child as $k=>$v}
                            {php}
                                $value = $key."/".$k;
                            {/php}
                            <input type="checkbox" name="roles" title="{$v}" value="{$value}" lay-skin="primary" {if in_array($value,$roles)}checked{/if}>
                            {/foreach}
                        </div>
                    </div>
                    {/foreach}
                </div>
            </fieldset>




            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    {:lang('edit')}
                </button>
            </div>
        </form>
    </div>
</div>
{include file="footer"}
<script>
    layui.use(['form', 'layer'], function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //监听提交
        form.on('submit(add)', function(data) {
            var roles=[]
            $("[name='roles']").each(function () {
                if($(this).is(":checked")){
                    roles.push($(this).val())
                }
            })
            data.field.roles = roles
            request("POST",'{:url("user/rolesedit")}',data.field,function (res,msg) {
                //发异步，把数据提交给php

                layer.alert(msg, {icon: 6}, function() {
                    xadmin.close();
                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                });
            })

            return false;
        });

    });
</script>